/**
 * @program: clms-second
 * @description: 汽车品牌控制层
 * @author: mitu_echo
 * @create: 2021-07-25 10:21
 **/

package com.second.lease.controller;

import com.second.common.pojo.R;
import com.second.lease.pojo.entity.CarBrand;
import com.second.lease.pojo.utils.UploadUtil;
import com.second.lease.pojo.vo.CarBrandVO;
import com.second.lease.service.CarBrandService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/carbrand")
public class CarBrandController {

    @Autowired
    private CarBrandService carBrandService;

    private List<String> urlList;

    /**
     * 查询汽车品牌
     * @param carBrandVO 查询汽车品牌实体类
     * @return
     */
    @ApiOperation("查询汽车品牌")
    @RequestMapping("/showCarBrand")
    private R showCarBrand(CarBrandVO carBrandVO) {

        return carBrandService.showCarBrand(carBrandVO);
    }

    /**
     * 添加汽车品牌
     * @param carBrand 汽车品牌实体类
     * @return
     */
    @ApiOperation("添加汽车品牌")
    @RequestMapping("/addCarBrand")
    private R addCarBrand(@RequestBody CarBrand carBrand) {

        return carBrandService.addCarBrand(carBrand);
    }

    /**
     * 修改汽车品牌
     * @param carBrand 汽车品牌实体类
     * @return
     */
    @ApiOperation("修改汽车品牌")
    @RequestMapping("/updayeCarBrand")
    private R updayeCarBrand(@RequestBody CarBrand carBrand) {

        return carBrandService.updayeCarBrand(carBrand);
    }

    /**
     * 删除汽车品牌
     * @param id 汽车品牌id
     * @return
     */
    @ApiOperation("删除汽车品牌")
    @RequestMapping("/deleteCarBrand")
    private R deleteCarBrand(Integer id) {

        return carBrandService.deleteCarBrand(id);
    }

    /**
     *
     * @param id 汽车品牌id
     * @param status 汽车状态值
     * @return
     */
    @ApiOperation("修改汽车状态")
    @RequestMapping("/updateStatus")
    private R updateStatus(Integer id,Integer status) {

        return carBrandService.updateStatus(id,status);
    }

    @ApiOperation("上传文件的接口")
    @RequestMapping("/upload")
    private Map Ipload (MultipartFile file) {
        // 将图片回显给前端
        urlList = UploadUtil.getUrl(file);
        HashMap map = new HashMap();
        if (urlList.size()>0) {
            map.put("img",urlList.get(0));
        }
        return map;
    }
}
